{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "Missing parentheses in call to 'print'. Did you mean print(\"Element is present at index % d\" % result)? (<ipython-input-1-9fcfd0c63771>, line 37)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-1-9fcfd0c63771>\"\u001b[1;36m, line \u001b[1;32m37\u001b[0m\n\u001b[1;33m    print \"Element is present at index % d\" % result\u001b[0m\n\u001b[1;37m                                          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m Missing parentheses in call to 'print'. Did you mean print(\"Element is present at index % d\" % result)?\n"
     ]
    }
   ],
   "source": [
    "# Python Program for recursive binary search. \n",
    "  \n",
    "# Returns index of x in arr if present, else -1 \n",
    "def binarySearch (arr, l, r, x): \n",
    "  \n",
    "    # Check base case \n",
    "    if r >= l: \n",
    "  \n",
    "        mid = l + (r - l)/2\n",
    "  \n",
    "        # If element is present at the middle itself \n",
    "        if arr[mid] == x: \n",
    "            return mid \n",
    "          \n",
    "        # If element is smaller than mid, then it  \n",
    "        # can only be present in left subarray \n",
    "        elif arr[mid] > x: \n",
    "            return binarySearch(arr, l, mid-1, x) \n",
    "  \n",
    "        # Else the element can only be present  \n",
    "        # in right subarray \n",
    "        else: \n",
    "            return binarySearch(arr, mid + 1, r, x) \n",
    "  \n",
    "    else: \n",
    "        # Element is not present in the array \n",
    "        return -1\n",
    "  \n",
    "# Test array \n",
    "arr = [ 2, 3, 4, 10, 40 ] \n",
    "x = 10\n",
    "  \n",
    "# Function call \n",
    "result = binarySearch(arr, 0, len(arr)-1, x) \n",
    "  \n",
    "if result != -1: \n",
    "    print \"Element is present at index % d\" % result \n",
    "else: \n",
    "    print \"Element is not present in array\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
